Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(color-contrast): correctly compute color-contrast of truncated children #3203

Merged
merged 12 commits into from
Oct 18, 2021

Conversation

straker
Copy link
Contributor

@straker straker commented Oct 12, 2021

This pr is dependent on #3207

The visuallyContains code was hard to understand what it was doing, so I refactored it to simplify it. Now it doesn't need to do the scrollTop and scrollLeft checking and only does a single compare to determine if the element is fully inside the other.

Closes issue: #2669

@straker straker requested a review from a team as a code owner October 12, 2021 21:00
Copy link
Contributor

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a few minor points

test/integration/rules/color-contrast/color-contrast.html Outdated Show resolved Hide resolved
* Assumes that |parent| is an ancestor of |node|.
* @param {Element} node
* @param {Element} parent
* @return {boolean} True if node is visually contained within parent
*/
function contains(node, parent) {
const rectBound = node.getBoundingClientRect();
const margin = 0.01;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the margin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the margin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rounding errors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, I would rather use Math.ceil and Math.floor to handle rounding issues rather than use a magic number. It makes it way more clear what the intent is.

lib/commons/color/get-background-stack.js Outdated Show resolved Hide resolved
lib/commons/color/get-background-color.js Outdated Show resolved Hide resolved
);
var expected = new axe.commons.color.Color(0, 255, 0, 1);
document.documentElement.style.background = orig;
assert.isNull(actual);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow... That's all I have to say about this.

test/commons/color/get-background-color.js Outdated Show resolved Hide resolved
straker and others added 3 commits October 13, 2021 07:51
@straker straker changed the title fix(color-contrast): fix truncation and account for body height of 0 fix(color-contrast): correctly compute color-contrast of truncation children Oct 13, 2021
WilcoFiers
WilcoFiers previously approved these changes Oct 14, 2021
lib/commons/color/get-background-color.js Outdated Show resolved Hide resolved
@straker straker changed the title fix(color-contrast): correctly compute color-contrast of truncation children fix(color-contrast): correctly compute color-contrast of truncated children Oct 14, 2021
Copy link
Contributor

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see margin be put back.

@straker straker merged commit ac7b2b5 into develop Oct 18, 2021
@straker straker deleted the visually-contains branch October 18, 2021 14:18
straker added a commit that referenced this pull request Oct 18, 2021
…ildren (#3203)

* fixes

* finalize

* sort

* test

* fix tests

* Update lib/commons/color/get-background-stack.js

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>

* fixes

* split out pr

* order

* rounding

Co-authored-by: Wilco Fiers <WilcoFiers@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants